<?=modules::run('home/top');?>

<body>

<!--date-->

<link rel="stylesheet" href="<?=PATH_URL.'static/js/date/jquery.ui.all.css'?>">
<script src="<?=PATH_URL.'static/js/date/jquery.ui.core.js'?>"></script>
<script src="<?=PATH_URL.'static/js/date/jquery.ui.datepicker.js'?>"></script>

<script type="text/javascript">
	jQuery(function() {
		jQuery( "#datepicker" ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: "dd/mm/yy",
			yearRange: "c-50:c+10",
		});
	});
</script>

<!--form-->

<script type="text/javascript" src="<?=PATH_URL.'static/js/form/jquery.validate.min.js'?>"></script>
<script type="text/javascript" src="<?=PATH_URL.'static/js/form/messages_vi.js'?>"></script>

<?php
	include_once('function/func.php');
	$cart=$this->session->userdata('Cart');
	if(!$cart){
		header('Location: '.PATH_URL);
	}
	$user=$this->session->userdata('ProfileInfo');
	if($user){
		$brithTmp=explode('-',$user['brithday']);
		$brith=$brithTmp[2].'/'.$brithTmp[1].'/'.$brithTmp[0];
	}
?>
<div id="wrapper">
	<header>
		<?=modules::run('home/head');?>
	</header>
	
	<nav id="nav">
		<?=modules::run('home/menu')?>
	</nav>
	
	<div class="content">
		<h1>Thanh toán</h1>
		
		<div class="frm_login">
        	<ul>
            	<li id="step_1" <?php if(!$user):?>class="active"<?php endif;?>>
                	<input type="hidden" id="login_checkout" value="1"/>
                	<div class="step_title">
                    	<span>1</span>
                        <p>Thông tin</p>
                    </div>
                    
                    <div id="show_step1" class="checkout_info" style="border-bottom: 1px solid #dddddd;padding-bottom: 10px;<?php if($user):?>display:none;<?php endif;?>">
                    	<div class="w49">
                            <h4>Thanh toán như 1 khách hàng mới</h4>
                            <p>Bằng cách tạo ra một tài khoản với cửa hàng của chúng tôi, bạn sẽ có thể di chuyển qua các quy trình kiểm tra nhanh hơn, lưu trữ nhiều địa chỉ vận chuyển, xem và theo dõi đơn đặt hàng của bạn trong tài khoản của bạn và nhiều hơn nữa.</p>
                            <article>
                            	<input type="radio" class="check_register" name="check_reg" value="1" checked="checked" />
                                <span>Tạo tài khoản</span>
                            </article>
                            <article>
                            	<input type="radio" class="check_no_register" name="check_reg" value="0"/>
                                <span>Không tạo tài khoản</span>
                            </article>
                            <dir class="button" style="margin-top: 43px;"><a onClick="chk_register(); return false;" style="color:#ffffff;text-decoration: none;" href="#">Tiếp tục</a></dir>
                        </div>
                        
                        <div class="w49" style="margin-left: 16px;">
                            <h4>Khách hàng đã đăng ký</h4>
                            <p>Nếu bạn đã có tài khoản, Xin vui lòng đăng nhập.</p>
                            <article>
                                <label>Email: <span>*</span></label>
                                <input type="text" name="email_login" id="email_login" value="" onKeyPress="return EnterLogin(event)" />
                            </article>
                            <article>
                                <label>Mật khẩu: <span>*</span></label>
                                <input type="password" name="passwork" id="passwork" value="" onKeyPress="return EnterLogin(event)"/>
                            </article>
                            <strong id="tbao"></strong>
                            <div class="log">
                                <a href="#">Bạn quên mật khẩu?</a>
                                <dir class="button" onclick="login(); return false;">Đăng nhập</dir>
                            </div>
                        </div>
                    </div>
                </li>
                
                <li id="step_2" <?php if($user):?>class="active"<?php endif;?> >
                	<div class="step_title">
                    	<span>2</span>
                        <p>Thông tin giao hàng</p>
                    </div>
                    
                    <div id="show_step2" class="frm_login" style="border-bottom: 1px solid #dddddd;padding-bottom: 10px;<?php if($user){?>display:block;<?php }else{?>display: none;<?php }?>">
                        <form id="fRegister" action="<?=PATH_URL.$module.'/'?>" method="post" enctype="multipart/form-data" >
                        <?php if(!$user):?>
                        <input type="hidden" value="1" id="checkout_register" />
                        <div class="w90 noRegister" style="border: none">
                            <h4 style="left: 20px;">Thông tin đăng nhập</h4>
                            
                            <div class="register">
                                <div class="one_register full">
                                    <label>Email: <span>*</span></label><span class="checkUser"></span>
                                    <input type="text" value="" name="email" id="email" class="required email" />
                                    <span class="error email"></span>
                                </div>
                                <div class="one_register full">
                                    <label>Mật khẩu: <span>*</span></label>
                                    <input minlength="6" class="required" type="password" value="" name="pass" id="pass" />
                                    <span class="error pass"></span>
                                </div>
                                <div class="one_register full">
                                    <label>Nhập lại mật khẩu: <span>*</span></label>
                                    <input type="password" value="" name="reg_pass" id="reg_pass" class="required" />
                                    <span class="error reg_pass"></span>
                                </div>
                            </div>
                        </div>
                        <?php endif;?>
                        
                        <div class="w90" style="border: none">
                            <h4 style="left: 20px;">Thông tin cá nhân</h4>
                            <input type="hidden" id="idProfile" value="<?php if($user):?><?=$user['id']?><?php endif;?>"/>
                            
                            <div class="register">
                                <div class="one_register 270">
                                    <label>Họ và tên: <span>*</span></label>
                                    <input class="required" type="text" value="<?php if($user):?><?=$user['name'];?><?php endif;?>" name="name" id="name" />
                                    <span class="error name"></span>
                                </div>
                                <?php if(!$user):?>
                                <div class="one_register full">
                                    <label>Ngày sinh:</label>
                                    <input type="text" value="<?php if($user):?><?=$brith;?><?php endif;?>" name="brithday" id="datepicker" />
                                </div>
                                <?php endif;?>
                                <div class="one_register full">
                                    <label>Số điện thoại: <span>*</span></label>
                                    <input type="text" value="<?php if($user):?>0<?=$user['phone'];?><?php endif;?>" name="phone" id="phone" />
                                    <span class="error phone"></span>
                                </div>
                                <div class="one_register 270">
                                    <label>Địa chỉ <?php if($user):?>giao hàng<?php endif;?>: <span>*</span></label>
                                    <textarea name="address" id="address"><?php if($user):?><?=$user['address'];?><?php endif;?></textarea>
                                    <span class="error address"></span>
                                </div>
                                <div class="one_register full">
                                    <label>Ghi chú: </label>
                                    <textarea name="note" id="note"></textarea>
                                </div>
                            </div>
                        </div>
                        
                        <dir style="margin: 30px 20px 0 0;" onclick="<?php if($user){?>check_continue(); return false;<?php }else{?>register(); return false;<?php } ?>" class="regis_bt button">Tiếp tục</dir>
                        
                        </form>
                    </div>
                </li>
                <li id="step_3">
                	<div class="step_title">
                    	<span>3</span>
                        <p>Thông tin thanh toán</p>
                    </div>
                    
                    <div id="show_step3" class="checkout_info" style="border-bottom: 1px solid #dddddd;padding-bottom: 10px;display: none;">
                    	<?php if($cart){?>
                    	<table cellpadding="0" cellspacing="0" border="0" width="100%">
                        	<tr>
                            	<th></th>
                                <th width="340px">Sản phẩm</th>
                                <th width="135px">Giá</th>
                                <th width="70px">Số lượng</th>
                                <th width="150px">Tộng cộng</th>
                            </tr>
                            <?php 
								$shop=rtrim($cart['shop'],'|');
								$arrShop=explode('|',$shop);
								$n=count($arrShop);
								$prcie_all='';
								for($i=0;$i<$n;$i++){
									$arrTmp=explode(',',$arrShop[$i]);
									$result=$this->productsModel->getOne($arrTmp[0]);
									 if($result[0]->price_new !=0 && $result[0]->promotion !=0){
										$price=$result[0]->price_new * $arrTmp[1];
									}else{
										$price=$result[0]->price_old * $arrTmp[1];
									}
									$prcie_all +=$price;
							?>
                            <tr>
                            	<td><img src="<?=PATH_URL.IMAGES_PRODUCTS.$result[0]->image?>" width="100" height="100" /></td>
                                <td><?=$result[0]->title;?></td>
                                <td align="center" class="price">					
									<?php if($result[0]->price_new != 0 && $result[0]->promotion != 0){?>
                                        <?=number_format($result[0]->price_new,0,',','.');?> vnđ
                                    <?php }else{?>
                                        <?=number_format($result[0]->price_old,0,',','.');?> vnđ
                                    <?php }?>
                                </td>
                                <td align="center"><?=$arrTmp[1]?></td>
                                <td align="center" class="price"><?=number_format($price,0,',','.');?> vnđ</td>
                            </tr>
                            <?php }?>
                            <tr>
                                <td align="right" colspan="4"><b style="color:#7E8DF8;font-size: 20px">Tổng giá tiền</b></td>
                                <td align="center" class="price"><?=number_format($prcie_all,0,',','.');?> vnđ</td>
                            </tr>
                        </table>
                        <?php }?>
                        <dir style="margin: 30px 0 0 0;" onclick="checkout()" class="regis_bt button">Thanh toán</dir>
                    </div>
                </li>
                <li id="step_4">
                	<div class="step_title">
                    	<span>4</span>
                        <p>Kết quả</p>
                    </div>
                    
                    <div id="show_step4" class="checkout_info" style="border-bottom: 1px solid #dddddd;padding-bottom: 10px;display: none;">
                    	
                    </div>
                </li>
            </ul>
			
		</div>
	</div><!--end content-->
	
	<footer>
		<?=modules::run('home/footer');?>
	</footer>
</div><!--end wrapper-->
</body>
</html>
